//
//  YTLiveModel.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/21.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTLivesModel.h"

@implementation YTLivesModel
- (NSString *)description
{
    return [self yy_modelDescription];
}

- (void)setCreated_at:(NSString *)created_at
{
    _created_at = [NSString timestampSwitchTime:created_at.integerValue andFormatter:@"yyyy-MM-dd HH:mm:ss"];
}

- (void)setContent:(NSString *)content
{
    _content = content;
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:content];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:8];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [content length])];
  
    self.attrStr = attributedString1.copy;
}

- (CGFloat)height
{
    return [self calcuRowHeght];
}

- (CGFloat)detailHeight
{
    return [self calcDetailHeight];
}

- (void)setPost_date:(NSString *)post_date
{
    _post_date = post_date;
    
    self.week = [NSString getWeekDay:post_date];
}

- (CGFloat)calcDetailHeight
{
    CGFloat height = 0.0f;
    CGFloat margin = 12.0f;
    CGFloat timeHeightM = 25.0f;
    
    height += timeHeightM;
    
    CGSize size = CGSizeMake(kScreenWidth - (2 * margin), MAXFLOAT);
    
    CGFloat timeH = [self.post_date boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height;
    
    // 计算高度
    height += timeH;
    
    CGFloat titleH = [self.post_title boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height;
    
    // 标题
    height += titleH;
    
    CGFloat contentH = [self.content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.height;
    
    // 内容高度
    height += contentH;
    
    // 底部按钮
    height += 18.5 + 64;
    
    return height;
}

#pragma mark: - 计算高度
- (CGFloat)calcuRowHeght
{
    CGFloat height = 0.0;
    CGFloat yuandianMargin = 18;
    CGFloat yuandian = 13;
    
    height += yuandian + yuandianMargin + 8;

    CGSize titleSize = CGSizeMake(kScreenWidth - 27 - (yuandian / 2) - 8 -43, MAXFLOAT);
    
    // 标题
    if (self.post_title.length > 0) {
        height += [self.post_title boundingRectWithSize:titleSize
                                           options:NSStringDrawingUsesLineFragmentOrigin
                                        attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.height;
    }

    // 标题距离正文
    height += 14;

    // 正文
    if (self.content.length > 0) {
        height += [self.content boundingRectWithSize:titleSize
                                             options:NSStringDrawingUsesLineFragmentOrigin
                                          attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12]}
                                             context:nil].size.height ;
    }
    
    
    // 正文距离分享
    height += 22;
    
    //height += 23;
    
    // 分享高度
    height += 30;
    
    return height;
}

// 获取中括号中字符串的内容
- (NSString *)fileterStrinWithString:(NSString *)str
{
    NSArray *array = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"【】"]];
    
    return array[1];
}
@end
